package com.datagateway.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;


/**
 * 数据网关配置属性类
 * 用于读取和管理应用程序的配置参数
 * 
 * @author Data Gateway Team
 * @version 1.0.0
 */
@Component
@ConfigurationProperties(prefix = "data-gateway")
public class DataGatewayProperties {

    /**
     * Kafka配置
     */
    private Kafka kafka = new Kafka();
    
    /**
     * Hive配置
     */
    private Hive hive = new Hive();
    
    /**
     * Groovy脚本配置
     */
    private Groovy groovy = new Groovy();
    
    /**
     * 性能配置
     */
    private Performance performance = new Performance();

    // Getter和Setter方法
    public Kafka getKafka() {
        return kafka;
    }

    public void setKafka(Kafka kafka) {
        this.kafka = kafka;
    }

    public Hive getHive() {
        return hive;
    }

    public void setHive(Hive hive) {
        this.hive = hive;
    }

    public Groovy getGroovy() {
        return groovy;
    }

    public void setGroovy(Groovy groovy) {
        this.groovy = groovy;
    }

    public Performance getPerformance() {
        return performance;
    }

    public void setPerformance(Performance performance) {
        this.performance = performance;
    }

    /**
     * Kafka配置类
     */
    public static class Kafka {
        /**
         * 消费者组ID
         */
        private String groupId = "data-gateway-group";
        
        /**
         * 主题列表
         */
        private String[] topics = {"data-topic"};
        
        /**
         * 消费者数量
         */
        private int consumerCount = 10;
        
        /**
         * 最大拉取记录数
         */
        private int maxPollRecords = 500;
        
        /**
         * 会话超时时间（毫秒）
         */
        private int sessionTimeoutMs = 30000;

        // Getter和Setter方法
        public String getGroupId() {
            return groupId;
        }

        public void setGroupId(String groupId) {
            this.groupId = groupId;
        }

        public String[] getTopics() {
            return topics;
        }

        public void setTopics(String[] topics) {
            this.topics = topics;
        }

        public int getConsumerCount() {
            return consumerCount;
        }

        public void setConsumerCount(int consumerCount) {
            this.consumerCount = consumerCount;
        }

        public int getMaxPollRecords() {
            return maxPollRecords;
        }

        public void setMaxPollRecords(int maxPollRecords) {
            this.maxPollRecords = maxPollRecords;
        }

        public int getSessionTimeoutMs() {
            return sessionTimeoutMs;
        }

        public void setSessionTimeoutMs(int sessionTimeoutMs) {
            this.sessionTimeoutMs = sessionTimeoutMs;
        }
    }

    /**
     * Hive配置类
     */
    public static class Hive {
        /**
         * 数据库名称
         */
        private String database = "default";
        
        /**
         * 表名称
         */
        private String table = "data_table";
        
        /**
         * 批量大小
         */
        private int batchSize = 1000;
        
        /**
         * 时间窗口（毫秒）
         */
        private long timeWindow = 30000;
        
        /**
         * 最大等待时间（毫秒）
         */
        private long maxWaitTime = 60000;
        
        /**
         * 缓冲区大小
         */
        private int bufferSize = 10000;
        
        /**
         * 最小文件大小（字节）
         */
        private long minFileSize = 134217728; // 128MB

        // Getter和Setter方法
        public String getDatabase() {
            return database;
        }

        public void setDatabase(String database) {
            this.database = database;
        }

        public String getTable() {
            return table;
        }

        public void setTable(String table) {
            this.table = table;
        }

        public int getBatchSize() {
            return batchSize;
        }

        public void setBatchSize(int batchSize) {
            this.batchSize = batchSize;
        }

        public long getTimeWindow() {
            return timeWindow;
        }

        public void setTimeWindow(long timeWindow) {
            this.timeWindow = timeWindow;
        }

        public long getMaxWaitTime() {
            return maxWaitTime;
        }

        public void setMaxWaitTime(long maxWaitTime) {
            this.maxWaitTime = maxWaitTime;
        }

        public int getBufferSize() {
            return bufferSize;
        }

        public void setBufferSize(int bufferSize) {
            this.bufferSize = bufferSize;
        }

        public long getMinFileSize() {
            return minFileSize;
        }

        public void setMinFileSize(long minFileSize) {
            this.minFileSize = minFileSize;
        }
    }

    /**
     * Groovy脚本配置类
     */
    public static class Groovy {
        /**
         * 脚本路径
         */
        private String scriptPath = "classpath:scripts/";
        
        /**
         * 默认脚本名称
         */
        private String defaultScript = "default-transform.groovy";
        
        /**
         * 缓存是否启用
         */
        private boolean cacheEnabled = true;
        
        /**
         * 缓存最大大小
         */
        private int cacheMaxSize = 100;
        
        /**
         * 缓存过期时间（秒）
         */
        private int cacheExpireAfterWrite = 3600;

        // Getter和Setter方法
        public String getScriptPath() {
            return scriptPath;
        }

        public void setScriptPath(String scriptPath) {
            this.scriptPath = scriptPath;
        }

        public String getDefaultScript() {
            return defaultScript;
        }

        public void setDefaultScript(String defaultScript) {
            this.defaultScript = defaultScript;
        }

        public boolean isCacheEnabled() {
            return cacheEnabled;
        }

        public void setCacheEnabled(boolean cacheEnabled) {
            this.cacheEnabled = cacheEnabled;
        }

        public int getCacheMaxSize() {
            return cacheMaxSize;
        }

        public void setCacheMaxSize(int cacheMaxSize) {
            this.cacheMaxSize = cacheMaxSize;
        }

        public int getCacheExpireAfterWrite() {
            return cacheExpireAfterWrite;
        }

        public void setCacheExpireAfterWrite(int cacheExpireAfterWrite) {
            this.cacheExpireAfterWrite = cacheExpireAfterWrite;
        }
    }

    /**
     * 性能配置类
     */
    public static class Performance {
        /**
         * 线程池核心大小
         */
        private int corePoolSize = 10;
        
        /**
         * 线程池最大大小
         */
        private int maxPoolSize = 50;
        
        /**
         * 队列容量
         */
        private int queueCapacity = 1000;
        
        /**
         * 线程空闲时间（秒）
         */
        private int keepAliveSeconds = 60;

        // Getter和Setter方法
        public int getCorePoolSize() {
            return corePoolSize;
        }

        public void setCorePoolSize(int corePoolSize) {
            this.corePoolSize = corePoolSize;
        }

        public int getMaxPoolSize() {
            return maxPoolSize;
        }

        public void setMaxPoolSize(int maxPoolSize) {
            this.maxPoolSize = maxPoolSize;
        }

        public int getQueueCapacity() {
            return queueCapacity;
        }

        public void setQueueCapacity(int queueCapacity) {
            this.queueCapacity = queueCapacity;
        }

        public int getKeepAliveSeconds() {
            return keepAliveSeconds;
        }

        public void setKeepAliveSeconds(int keepAliveSeconds) {
            this.keepAliveSeconds = keepAliveSeconds;
        }
    }
}
